<template>
  <el-container>
    <el-header class="m-header">
      <!-- 搜索表单 -->
      <el-form style="padding-top: 1px;padding-bottom: 5px"
               :model="where"
               label-width="77px"
               class="ele-form-search"
               @keyup.enter.native="reload"
               @submit.native.prevent>
        <el-row>
          <el-col :lg="4" :md="12">
            <el-form-item label="入库单号:">
              <el-input size="mini"
                        clearable
                        v-model="where.vbillcode"
                        placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :md="4" :sm="12">
            <el-form-item label="起始日期:">
              <el-date-picker size="mini" v-model="where.riqiBegin" type="date" format='yyyy-MM-dd' value-format='yyyy-MM-dd' placeholder="选择日期" clearable class="ele-fluid"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :md="4" :sm="12">
            <el-form-item label="结束日期:">
              <el-date-picker size="mini" v-model="where.riqiEnd" type="date" format='yyyy-MM-dd' value-format='yyyy-MM-dd' placeholder="选择日期" clearable class="ele-fluid"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :lg="4" :md="12">
            <el-form-item label="客户名称:">
              <el-input size="mini"
                        clearable
                        v-model="where.custname"
                        placeholder="输入客户编码或客户名称查询"/>
            </el-form-item>
          </el-col>
          <el-col :lg="4" :md="12">
            <el-form-item label="仓库:" label-width="50px">
              <el-select size="mini"
                         clearable
                         v-model="where.storename"
                         placeholder="请选择仓库"
                         class="ele-fluid">
                <el-option v-for="item in storenameList" :key="item.storename" :label="item.storename" :value="item.storename"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :lg="4" :md="12">
            <el-form-item label="操作状态:" label-width="80px">
              <el-select size="mini"
                         clearable
                         v-model="where.opertype"
                         placeholder="请选择操作状态"
                         class="ele-fluid">
                <el-option label="已标记" value="Y"></el-option>
                <el-option label="未标记" value="N"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :lg="4" :md="12">
            <el-form-item label="所属板块:">
              <el-select size="mini"
                         clearable
                         v-model="where.ssbk"
                         placeholder="请选择所属板块"
                         class="ele-fluid">
                <el-option v-for="item in ssbkList" :label="item" :value="item" :key="item" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :lg="4" :md="12">
            <div class="ele-form-actions" style="padding-top: 5px;padding-left: 5px">
              <el-button
                type="primary"
                icon="el-icon-search"
                class="ele-btn-icon"
                size="mini"
                @click="reload">查询
              </el-button>
              <el-button
                type="primary"
                icon="el-icon-download"
                class="ele-btn-icon"
                size="mini"
                @click="exportData">导出
              </el-button>
              <el-button @click="reset" size="mini" class="ele-btn-icon">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </el-header>
    <el-main>
      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :where="where"
        :datasource="url"
        :columns="columns"
        :need-page="true"
        :toolbar="false"
        :selection.sync="selection"
        highlight-current-row
        @row-click="rowClick"
        @row-dblclick="showReturnForm"
        height="calc((100vh - 200px)/2)">
        <template slot="realreason" slot-scope="{row}">
          <el-select class="my-el-select" v-model="row.realreason">
            <el-option value="客户调换产品">客户调换产品</el-option>
            <el-option value="其他原因">其他原因</el-option>
          </el-select>
        </template>
        <template slot="remark" slot-scope="{row}">
          <textarea  v-model="row.remark" rows="2" style="width: 95%"></textarea>
        </template>
        <!-- 表头工具栏 -->
        <template slot="toolbar" v-if="false">
          <el-button
            size="small"
            type="primary"
            icon="el-icon-plus"
            class="ele-btn-icon"
            @click="openEdit(null)"
            v-if="permission.includes('sys:c37infckscbillnew:add')">添加
          </el-button>
          <el-button
            size="small"
            type="danger"
            icon="el-icon-delete"
            class="ele-btn-icon"
            @click="removeBatch"
            v-if="permission.includes('sys:c37infckscbillnew:dall')">删除
          </el-button>
        </template>
        <!-- 操作列 -->
        <!-- 操作列 -->
        <template slot="action" slot-scope="{row}">
          <el-link
            type="primary"
            :underline="false"
            icon="el-icon-upload2"
            @click="openEdit(row)"
          >NC回写
          </el-link>
          <el-link
            type="success"
            slot="reference"
            :underline="false"
            icon="el-icon-document"
            @click="openLog(row)"
          >日志
          </el-link>
          <el-link v-if="false"
                   type="primary"
                   :underline="false"
                   icon="el-icon-search"
                   @click="openDetail(row)"
          >单据明细
          </el-link>

        </template>
      </ele-pro-table>
    </el-main>
    <el-footer class="m-footer">
      <el-tabs v-model="activeName" @tab-click="handleClick" type="card">
        <el-tab-pane label="物料信息" name="first">
          <ele-pro-table
            ref="tableMaterial"
            :where="where"
            :datasource="orderDetail"
            :columns="columnsMaterial"
            :selection.sync="selectionMaterial"
            @row-click="materialRowClick"
            @row-dblclick="showReturnForm"
            :need-page="false"
            :toolbar="false"
            height="calc((100vh - 250px)/2)">
            <!-- 表头工具栏 -->
            <template slot="toolbar" v-if="false">
              <el-button
                size="small"
                type="primary"
                icon="el-icon-plus"
                class="ele-btn-icon"
                @click="openEdit(null)"
                v-if="permission.includes('sys:c37infckscbillnew:add')">添加
              </el-button>
              <el-button
                size="small"
                type="danger"
                icon="el-icon-delete"
                class="ele-btn-icon"
                @click="removeBatch"
                v-if="permission.includes('sys:c37infckscbillnew:dall')">删除
              </el-button>
            </template>
            <!-- 操作列 -->
            <!-- 操作列 -->
            <template slot="action" slot-scope="{row}">
              <el-link
                type="primary"
                :underline="false"
                icon="el-icon-upload2"
                @click="openEdit(row)"
              >NC回写
              </el-link>
              <el-link
                type="success"
                slot="reference"
                :underline="false"
                icon="el-icon-document"
                @click="openLog(row)"
              >日志
              </el-link>
              <el-link v-if="false"
                       type="primary"
                       :underline="false"
                       icon="el-icon-search"
                       @click="openDetail(row)"
              >单据明细
              </el-link>

            </template>
          </ele-pro-table>

        </el-tab-pane>
        <el-tab-pane label="原销售信息" name="second">
          <ele-pro-table
            ref="tableSO"
            :where="where"
            :datasource="orderInvoice"
            :columns="columnsSO"
            :need-page="false"
            :toolbar="false"
            height="calc((100vh - 250px)/2)">
            <!-- 表头工具栏 -->
            <template slot="toolbar" v-if="false">
              <el-button
                size="small"
                type="primary"
                icon="el-icon-plus"
                class="ele-btn-icon"
                @click="openEdit(null)"
                v-if="permission.includes('sys:c37infckscbillnew:add')">添加
              </el-button>
              <el-button
                size="small"
                type="danger"
                icon="el-icon-delete"
                class="ele-btn-icon"
                @click="removeBatch"
                v-if="permission.includes('sys:c37infckscbillnew:dall')">删除
              </el-button>
            </template>
            <!-- 操作列 -->
            <!-- 操作列 -->
            <template slot="action" slot-scope="{row}">
              <el-link
                type="primary"
                :underline="false"
                icon="el-icon-upload2"
                @click="openEdit(row)"
              >NC回写
              </el-link>
              <el-link
                type="success"
                slot="reference"
                :underline="false"
                icon="el-icon-document"
                @click="openLog(row)"
              >日志
              </el-link>
              <el-link v-if="false"
                       type="primary"
                       :underline="false"
                       icon="el-icon-search"
                       @click="openDetail(row)"
              >单据明细
              </el-link>

            </template>
          </ele-pro-table>
        </el-tab-pane>
        <el-tab-pane label="退货入库信息" name="third">
          <ele-pro-table
            ref="tableRK"
            :where="where"
            :datasource="orderReturnInvoice"
            :columns="columnsRK"
            :need-page="false"
            :toolbar="false"
            height="calc((100vh - 250px)/2)">
            <!-- 表头工具栏 -->
            <template slot="toolbar" v-if="false">
              <el-button
                size="small"
                type="primary"
                icon="el-icon-plus"
                class="ele-btn-icon"
                @click="openEdit(null)"
                v-if="permission.includes('sys:c37infckscbillnew:add')">添加
              </el-button>
              <el-button
                size="small"
                type="danger"
                icon="el-icon-delete"
                class="ele-btn-icon"
                @click="removeBatch"
                v-if="permission.includes('sys:c37infckscbillnew:dall')">删除
              </el-button>
            </template>
            <!-- 操作列 -->
            <!-- 操作列 -->
            <template slot="action" slot-scope="{row}">
              <el-link
                type="primary"
                :underline="false"
                icon="el-icon-upload2"
                @click="openEdit(row)"
              >NC回写
              </el-link>
              <el-link
                type="success"
                slot="reference"
                :underline="false"
                icon="el-icon-document"
                @click="openLog(row)"
              >日志
              </el-link>
              <el-link v-if="false"
                       type="primary"
                       :underline="false"
                       icon="el-icon-search"
                       @click="openDetail(row)"
              >单据明细
              </el-link>

            </template>
          </ele-pro-table>
        </el-tab-pane>
        <el-tab-pane label="退货发票信息" name="fourth">
          <ele-pro-table
            ref="tableFP"
            :where="where"
            :datasource="orderReturnInvoice"
            :columns="columnsFP"
            :need-page="false"
            :toolbar="false"
            height="calc((100vh - 250px)/2)">
            <!-- 表头工具栏 -->
            <template slot="toolbar" v-if="false">
              <el-button
                size="small"
                type="primary"
                icon="el-icon-plus"
                class="ele-btn-icon"
                @click="openEdit(null)"
                v-if="permission.includes('sys:c37infckscbillnew:add')">添加
              </el-button>
              <el-button
                size="small"
                type="danger"
                icon="el-icon-delete"
                class="ele-btn-icon"
                @click="removeBatch"
                v-if="permission.includes('sys:c37infckscbillnew:dall')">删除
              </el-button>
            </template>
            <!-- 操作列 -->
            <!-- 操作列 -->
            <template slot="action" slot-scope="{row}">
              <el-link
                type="primary"
                :underline="false"
                icon="el-icon-upload2"
                @click="openEdit(row)"
              >NC回写
              </el-link>
              <el-link
                type="success"
                slot="reference"
                :underline="false"
                icon="el-icon-document"
                @click="openLog(row)"
              >日志
              </el-link>
              <el-link v-if="false"
                       type="primary"
                       :underline="false"
                       icon="el-icon-search"
                       @click="openDetail(row)"
              >单据明细
              </el-link>

            </template>
          </ele-pro-table>
        </el-tab-pane>
      </el-tabs>
    </el-footer>
    <LogList
      :dataItem="current"
      :visible.sync="showLog"
    />
    <ReturnForm :visible="showReturn" :data="selection" :material="selectionMaterial"
                @done="updateMainReason"
                @donematerial="updateMaterialReason"
                @update:visible="updateShowReturn"/>
    <!-- 编辑弹窗 -->
    <!-- <c37infckscbillnew-edit
      :data="current"
      :visible.sync="showEdit"
      @done="reload"/> -->
  </el-container>
</template>

<script>
import { mapGetters } from "vuex";
import LogList from '../../purchase/inbound/loglist.vue';
import ReturnForm from './return-form.vue'
import XLSX from "xlsx";
// import C37InfCkScBillNewEdit from './c37infckscbillnew-edit';

export default {
  name: 'ReturnOrder',
  // components: {C37InfCkScBillNewEdit},
  components: {LogList,ReturnForm},
  computed: {
    ...mapGetters(["permission"]),
  },
  data() {
    return {
      // 表格数据接口
      url: '/return/index',
      urlb: '/return/orderdetail',
      // 表格列配置
      columns: [
        {
          columnKey: 'index',
          type: 'index',
          width: 45,
          align: 'center',
          fixed: "left"
        },
        {
          prop: 'rkdbilldate',
          label: '入库日期',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'rkvbillcode',
          label: '入库单号',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'center'
        },
        {
          prop: 'ssbk',
          label: '所属版块',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'center'
        },
        {
          prop: 'custcode',
          label: '客户编码',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'custname',
          label: '客户名称',
          showOverflowTooltip: true,
          minWidth: 160,
          align: 'left'
        },
        {
          prop: 'rksl',
          label: '入库数量',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'storename',
          label: '仓库名称',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'left'
        },
        {
          prop: 'realreason',
          label: '业务退货原因',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'center',
          // slot: 'realreason'
        },
        {
          prop: 'remark',
          label: '备注',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'center',
          // slot: 'remark'
        },
        {
          prop: 'opertype',
          label: '后续处理',
          showOverflowTooltip: true,
          minWidth: 80,
          align: 'center',
          // slot: 'remark'
        },
        // {
        //   prop: 'sfrk',
        //   label: '是否入库',
        //   showOverflowTooltip: true,
        //   minWidth: 80,
        //   align: 'center',
        //   // slot: 'remark'
        // },
        // {
        //   prop: 'returnreason',
        //   label: '退货原因',
        //   showOverflowTooltip: true,
        //   minWidth: 140,
        //   align: 'center'
        // },
        {
          prop: 'addrname',
          label: '退货地址',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'left'
        },
        {
          prop: 'provinces',
          label: '省区',
          showOverflowTooltip: true,
          minWidth: 60,
          align: 'center'
        },
        {
          prop: 'deptname',
          label: '部门',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'psnname',
          label: '业务员',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'billmaker',
          label: '制单人',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        // {
        //   prop: '',
        //   label: '状态',
        //   showOverflowTooltip: true,
        //   minWidth: 100,
        //   align: 'center'
        // },
        {
          prop: 'billtypename',
          label: '单据类型',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        // {
        //   prop: 'dbilldate',
        //   label: '申请日期',
        //   showOverflowTooltip: true,
        //   minWidth: 100,
        //   align: 'center'
        // },
        // {
        //   prop: 'vbillcode',
        //   label: '申请单号',
        //   showOverflowTooltip: true,
        //   minWidth: 140,
        //   align: 'center'
        // },
        // {
        //   prop: 'ntotalnum',
        //   label: '申请总数量',
        //   showOverflowTooltip: true,
        //   minWidth: 100,
        //   align: 'center'
        // },
        // {
        //   prop: 'ntotalorigmny',
        //   label: '总金额（含税）',
        //   showOverflowTooltip: true,
        //   minWidth: 130,
        //   align: 'center'
        // },
        // {
        //   prop: 'vbdef13',
        //   label: '来源系统',
        //   showOverflowTooltip: true,
        //   minWidth: 160,
        //   align: 'center'
        // },
        // {
        //   prop: 'hsl',
        //   label: '箱规',
        //   showOverflowTooltip: true,
        //   minWidth: 100,
        //   align: 'center'
        // },
        {
          prop: 'ts',
          label: 'TS',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'center'
        },
        {
          prop: 'cgeneralhid',
          label: '主表主键',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'center'
        },
        // {
        //   columnKey: 'action',
        //   label: '操作',
        //   width: 160,
        //   align: 'center',
        //   resizable: false,
        //   slot: 'action',
        //   fixed: "right"
        // }
      ],
      columnsMaterial:[
        {
          columnKey: 'index',
          type: 'index',
          width: 45,
          align: 'center',
        },
        {
          prop: 'ssbk',
          label: '所属板块',
          showOverflowTooltip: true,
          minWidth: 180,
          align: 'center'
        },
        {
          prop: 'invcode',
          label: '药品编码',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'invname',
          label: '药品通用名',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'center'
        },
        {
          prop: 'gg',
          label: '规格',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'center'
        },
        {
          prop: 'returnreason',
          label: '退货原因',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'center'
        },
        {
          prop: 'nnum',
          label: '入库数量',
          showOverflowTooltip: true,
          minWidth: 80,
          align: 'center'
        },
        // {
        //   prop: 'nprice',
        //   label: '无税单价',
        //   showOverflowTooltip: true,
        //   minWidth: 80,
        //   align: 'center'
        // },
        // {
        //   prop: 'ntaxmny',
        //   label: '无税金额',
        //   showOverflowTooltip: true,
        //   minWidth: 80,
        //   align: 'center'
        // },
        {
          prop: 'vlotno',
          label: '批号',
          showOverflowTooltip: true,
          minWidth: 130,
          align: 'center'
        },
        {
          prop: 'vinvaliddate',
          label: '有效期至',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'vmanufacturer',
          label: '生产企业',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'center'
        },
        {
          prop: 'realreason',
          label: '业务退货原因',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'center',
          // slot: 'realreason'
        },
        {
          prop: 'remark',
          label: '备注',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'center',
          // slot: 'remark'
        },
        {
          prop: 'opertype',
          label: '后续处理',
          showOverflowTooltip: true,
          minWidth: 80,
          align: 'center',
          // slot: 'remark'
        },
        {
          prop: 'cgeneralhid',
          label: '主表主键',
          showOverflowTooltip: true,
          minWidth: 165,
          align: 'center'
        },
        {
          prop: 'cgeneralbid',
          label: '子表主键',
          showOverflowTooltip: true,
          minWidth: 165,
          align: 'center'
        },

      ],
      columnsSO:[
        {
          columnKey: 'index',
          type: 'index',
          width: 45,
          align: 'center',
        },
        {
          prop: 'vbillcode',
          label: '原订单号',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'orderdate',
          label: '原订单日期',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'center'
        },
        {
          prop: 'vsrccode',
          label: '原出库单号',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'center'
        },
        // {
        //   prop: 'nnum',
        //   label: '原出库日期',
        //   showOverflowTooltip: true,
        //   minWidth: 80,
        //   align: 'center'
        // },
        {
          prop: 'vgoldtaxcode',
          label: '原发票号',
          showOverflowTooltip: true,
          minWidth: 80,
          align: 'center'
        },
        {
          prop: 'dbilldate',
          label: '原发票日期',
          showOverflowTooltip: true,
          minWidth: 80,
          align: 'center'
        },
        {
          prop: 'invoicenum',
          label: '发票数量',
          showOverflowTooltip: true,
          minWidth: 80,
          align: 'center'
        },
        {
          prop: 'nqtorigtaxprice',
          label: '发票含税单价',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'nqtorigprice',
          label: '发票无税单价',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'norigtaxmny',
          label: '发票价税合计',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'center'
        },
        {
          prop: 'norigmny',
          label: '无税合计',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'center'
        },
        {
          prop: '',
          label: '原件数',
          showOverflowTooltip: true,
          minWidth: 165,
          align: 'center'
        },

      ],
      columnsRK:[
        {
          columnKey: 'index',
          type: 'index',
          width: 45,
          align: 'center',
        },
        {
          prop: 'checkdate',
          label: '退货入库时间',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'invcode',
          label: '药品编码',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'invname',
          label: '药品名称',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'left'
        },
        {
          prop: 'vlotno',
          label: '批号',
          showOverflowTooltip: true,
          minWidth: 130,
          align: 'center'
        },
        {
          prop: 'hgsl',
          label: '验收合格数量',
          showOverflowTooltip: true,
          minWidth: 140,
          maxWidth: 150,
          align: 'center'
        },
        {
          prop: 'bhgsl',
          label: '验收不合格数量',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'center'
        },
        // {
        //   prop: 'nnum',
        //   label: '退货入库时间',
        //   showOverflowTooltip: true,
        //   minWidth: 80,
        //   align: 'center'
        // },
        // {
        //   prop: 'rksl',
        //   label: '入库数量（合格+不合格）',
        //   showOverflowTooltip: true,
        //   minWidth: 80,
        //   align: 'center'
        // },
        // {
        //   prop: 'ntaxprice',
        //   label: '实际入库件数',
        //   showOverflowTooltip: true,
        //   minWidth: 80,
        //   align: 'center'
        // },

      ],
      columnsFP:[
        {
          columnKey: 'index',
          type: 'index',
          width: 45,
          align: 'center',
        },
        {
          prop: 'vdef7',
          label: '红票通知单',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'vgoldtaxcode',
          label: '红票金税号',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'center'
        },
        {
          prop: 'vlotno',
          label: '批号',
          showOverflowTooltip: true,
          minWidth: 130,
          align: 'center'
        },
        {
          prop: 'dbilldate',
          label: '红票日期',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'center'
        },
        // {
        //   prop: 'nnum',
        //   label: '蓝票金税号',
        //   showOverflowTooltip: true,
        //   minWidth: 80,
        //   align: 'center'
        // },
        // {
        //   prop: 'nprice',
        //   label: '蓝票日期',
        //   showOverflowTooltip: true,
        //   minWidth: 80,
        //   align: 'center'
        // },
        {
          prop: 'nqtorigtaxprice',
          label: '含税单价',
          showOverflowTooltip: true,
          minWidth: 80,
          align: 'center'
        },
        {
          prop: 'nqtorigprice',
          label: '无税单价',
          showOverflowTooltip: true,
          minWidth: 80,
          align: 'center'
        },
        {
          prop: 'nastnum',
          label: '数量',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'norigmny',
          label: '无税金额',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
      ],
      // 表格搜索条件
      where: {riqiBegin:this.getFromDate(),riqiEnd:new Date(),status:'是'},
      // 表格选中数据
      selection: [],
      selectionMaterial:[],
      // 当前编辑数据
      current: null,
      // 是否显示编辑弹窗
      showEdit: false,
      showLog: false,
      showDetail:false,
      showReturn:false,
      activeName:'first',
      isFirst:true,
      isSecond:false,
      isThird:false,
      isFourth:false,
      //退货单明细
      orderDetail:[],
      //退货发票
      orderInvoice:[],
      orderReturnInvoice:[],
      soList:[],
      rkList:[],
      fpList:[],
      storenameList:[],
      ssbkList:[],
    };
  },
  mounted() {
    this.getStoreList()
    this.getSsbkList();
  },
  methods: {
    async getStoreList(){
      var res = await this.$http.get('/return/storelist');
      if(res.status==200)
      {
        this.storenameList = res.data.data;
      }

    },
    async getSsbkList(){
      var res = await this.$http.get('/return/ssbk');
      if(res.status==200)
      {
        this.ssbkList = res.data.data;
      }

    },
    /* 导出数据 */
    exportData() {
      let array = [['入库日期', '入库单号', '所属版块', '客户编码','客户名称', '入库数量','仓库名称','业务退货原因','备注', '后续处理', '退货地址' ,'省区','部门','业务员','制单人', '单据类型','主表主键', 'ts']];
      const loading = this.$loading({lock: true});
      let url = "/return/index?page=1&limit=20000000";
      // let param = "";
      // Object.keys(this.where).forEach(key=>{
      //   if(this.where[key] && this.where[key]!="")
      //   {
      //     param+="&"+key+"="+this.where[key];
      //   }
      // });
      //url = url+param;
      this.$http.get(url,{params:this.where}).then(res => {
        loading.close();
        if (res.data.code === 0) {
          res.data.data.records.forEach(d => {
            array.push([
              d.rkdbilldate,
              d.rkvbillcode,
              d.ssbk,
              d.custcode,
              d.custname,
              d.rksl,
              d.storename,
              d.realreason,
              d.remark,
              d.opertype,
              d.addrname,
              d.provinces,
              d.deptname,
              d.psnname,
              d.billmaker,
              d.billtypename,
              d.cgeneralhid,
              d.ts
            ]);
          });
          this.$util.exportSheet(XLSX, array, '退货订单');
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        loading.close();
        this.$message.error(e.message);
      });
    },
    setBilldate(){
      if(this.where.status=='否')
      {
        this.where.riqiBegin='';
        this.where.riqiEnd = '';
      }
      else if(this.where.status=='是')
      {
        this.where.riqiBegin = this.getFromDate();
        this.where.riqiEnd = new Date();
      }
    },
    statusFormat(row, column,cellValue) {
      const daterc = row[column.property]
      if(daterc !=null){
        return cellValue=="N"?"已同步":"未同步";
      }
    },
    updateMainReason(reason,remark,optype){
      this.selection[0].realreason = reason;
      this.selection[0].remark = remark;
      this.selection[0].opertype = optype;
      for(let v of this.orderDetail)
      {
        v.realreason = reason;
        v.remark = remark;
      }
      var param = {
        cgeneralhid:this.selection[0].cgeneralhid,
        storename:this.selection[0].storename,
        csaleorderbid:'',
        realreason: reason,
        opertype: optype,
        remark: this.selection[0].remark
      };
      this.$http.post('/return/savereturn/',param).then(res => {
        if (res.data.code === 0) {
          this.$message.success(res.data.msg);
          this.rowClick(this.selection[0]);

          //this.reload();
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        this.$message.error(e.message);
      });

    },
    updateMaterialReason(reason,remark,optype){
      this.selectionMaterial[0].realreason = reason;
      this.selectionMaterial[0].remark = remark;
      this.selectionMaterial[0].opertype = optype;
      var param = {
        cgenebralhid:this.selection[0].cgeneralhid,
        cgeneralbid:this.selectionMaterial[0].cgeneralbid,
        realreason: reason,
        opertype: optype,
        remark: this.selectionMaterial[0].remark
      };
      this.$http.post('/return/savereturn/',param).then(res => {
        if (res.data.code === 0) {
          this.$message.success(res.data.msg);
          //this.reload();
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        this.$message.error(e.message);
      });



    },
    updateShowReturn(value)
    {
      this.showReturn = value;
    },
    showReturnForm(){
      this.showReturn = true;
    },
    handleClick(tab) {
      if (tab.name === 'first') {
        this.isFirst = true
        this.isSecond = false
        this.isThird = false
        this.isFourth = false
      }
      else if (tab.name === 'second') {
        this.isFirst = false
        this.isSecond = true
        this.isThird = false
        this.isFourth = false

      }
      else if (tab.name === 'third') {
        this.isFirst = false
        this.isSecond = false
        this.isThird = true
        this.isFourth = false

      }
      else if (tab.name === 'fourth') {
        this.isFirst = false
        this.isSecond = false
        this.isThird = false
        this.isFourth = true

      }
    },
    materialRowClick(row)
    {
      this.selectionMaterial = [];
      this.$refs.tableMaterial.clearSelection();
      this.selectionMaterial.push(row);
      this.$refs.tableMaterial.toggleRowSelection(row,true);

    },
    async rowClick(row)
    {
      //console.log(row);
      this.selection = [];
      this.selectionMaterial = [];
      this.$refs.table.clearSelection();
      this.selection.push(row);
      this.$refs.table.toggleRowSelection(row,true);
      var res = await this.$http.get('/return/orderdetail/'+row.cgeneralhid);
      if(res.status==200)
      {
        this.orderDetail = res.data.data;
      }
      var res2 = await this.$http.get('/return/orderinvoice/'+row.csaleorderid);
      if(res2.status==200)
      {
        this.orderInvoice = res2.data.data;
      }
      var res3 = await this.$http.get('/return/ordercheck/'+row.rkvbillcode);
      if(res3.status==200)
      {
        this.orderReturnInvoice = res3.data.data;
      }

    },
    getFromDate() {
      const timeOne = new Date()
      const year = timeOne.getFullYear()
      let month = timeOne.getMonth()
      let day = 1
      //month = month < 10 ? '0' + month : month
      //day = day < 10 ? '0' + day : day
      ///const NOW_MONTHS_AGO = `${year}-${month}-${day}`
      return new Date(year,month,day);
    },
    /* 刷新表格 */
    reload() {
      this.$refs.table.reload({where: this.where});
    },
    /* 重置搜索 */
    reset() {
      this.where = {riqiBegin:this.getFromDate(),riqiEnd:new Date()};
      this.reload();
    },
    openLog(row){
      console.log(row);
      this.current = row;
      this.showLog = true;
    },
    openDetail(row){
      this.current = row;
      this.showDetail = true;
    },

    /* 显示编辑 */
    openEdit(row) {
      this.$confirm('确定要将选中的销售出库记录回写至NC吗?', '提示', {
        type: 'warning'
      }).then(() => {
        const loading = this.$loading({lock: true});
        this.$http.post('/shyp/zyyptck/', [row.csaleinvoicebid]).then(res => {
          loading.close();
          if (res.data.code === 0) {
            this.$message.success(res.data.msg);
            this.reload();
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch(e => {
          loading.close();
          this.$message.error(e.message);
        });
      }).catch(() => {
      });
    },
    /* 删除 */
    remove(row) {
      const loading = this.$loading({lock: true});
      this.$http.delete('/c37infckscbillnew/delete', {id: row.id}).then(res => {
        loading.close();
        if (res.data.code === 0) {
          this.$message.success(res.data.msg);
          this.reload();
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        loading.close();
        this.$message.error(e.message);
      });
    },
    /* 批量删除 */
    removeBatch() {
      if (!this.selection.length) {
        this.$message.error('请至少选择一条数据');
        return;
      }
      this.$confirm('确定要删除选中的销售出库/购进退出上传单表吗?', '提示', {
        type: 'warning'
      }).then(() => {
        const loading = this.$loading({lock: true});
        this.$http.delete('/c37infckscbillnew/delete', {id: this.selection.map(d => d.id)}).then(res => {
          loading.close();
          if (res.data.code === 0) {
            this.$message.success(res.data.msg);
            this.reload();
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch(e => {
          loading.close();
          this.$message.error(e.message);
        });
      }).catch(() => {
      });
    },
  }
}
</script>

<style scoped>
.m-header {
  height: 72px !important;
}
.m-footer {
  height: calc((100vh - 160px)/2) !important;
}
.el-row {
  margin-bottom: -5px;
  margin-top: 1px;
  display: flex;
  flex-wrap: wrap
}
/*对Tab标签页进行样式调整*/
.el-tabs__item.is-active {
  color: rgb(11, 150, 151);
}

.el-tabs__active-bar {
  background-color: rgb(11, 150, 151);
}

.el-tabs__item:hover {
  color: rgb(11, 150, 151);
}

.el-tabs {
  height: 100% !important;
  width: 100% !important;

}

.el-tabs__content {
  height: calc(100% - 55px);
  padding: 1px;
}
.el-tabs--border-card > .el-tabs__content {
  padding: 15px;
}

.el-tab-pane {
  height: 100%;
}

.el-tabs__header {
  padding: 0 30px;
}
.el-form-item{
  margin-bottom: 2px;
}
.ele-body {
  padding: 1px;
}
.el-dialog__body {
  padding-top: 2px;
  color: var(--color-text-regular);
  font-size: 14px;
  word-break: break-all;
}

.my-el-select /deep/ .el-input__inner::placeholder {
  color: #296dd3;
  text-align: left;
  font-size:10px;
  line-height: 30px;

}


</style>
